#include "stdafx.h"
#include "PatientEventHandler.h"
#include "PatientEvent.h"
#include <time.h>
#include <iostream>
#include<fstream>
#include <sstream> 

namespace Network
{
	PatientEventHandler::PatientEventHandler()
	{
		this->reactor = reactor;
		reactor->register_handler(this, READ_EVENT);
	}

	PatientEventHandler::PatientEventHandler(const SOCK_Stream &stream)
	{
		peerStream = stream;
	}

	void PatientEventHandler::HandleEvent(HANDLE handle, EventType event_type)
	{

	}

	HANDLE PatientEventHandler::GetHandle() 
	{
		return peerStream.GetHandle();
	}

	bool PatientEventHandler::IsRunning()
	{
		return status;
	}

/*
	std::string PatientEventHandler::handle(unsigned char* data)
	{
		ifstream patients_file;
		PatientEvent n_evnt = PatientEvent();
		long file_point;
		char *buffer;
		size_t result;
		Network::SOCK_Stream *serverStream;


		if (0 != deserializePatientEvent((char*)data, &n_evnt)) {
			cout << "Error in deserialization of PatientEvent!";
		}

		//Here we need a search to a file with the given number!
		//pFile = fopen("patients.txt","r");
		patients_file.open("patients.txt");

		if  (patients_file.is_open()){

		//file_point = ftell(pFile);
		
		//buffer = (char*) malloc (sizeof(char)*file_point);
		//fseek(pFile,0,SEEK_SET);


		std::ostringstream out;
		out << "Patient id is: " << n_evnt.type  << "\n and his value is: " << n_evnt.value << "\n";
		std::string str( out.str());
		return str;

		//fread(buffer,1,file_point,pFile);
		buffer = (char*) malloc(sizeof(patients_file));
		ZeroMemory(buffer,sizeof(buffer));
		//while(!patients_file.eof()){
			patients_file.read(buffer,sizeof(patients_file));

		cout << buffer;
		 int bytesSent = serverStream->send(buffer, sizeof(buffer), 0);
		//}
		patients_file.close();
		}
		else
		{
			cout<< "file not opened";
		}

		return "ERROR";
	}
*/
}